﻿package com.athena.ui {
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;

	public class ItemList extends Sprite
	{
		private var _label:String;
		public var allButtons:Array;
		public var up:MovieClip;
		public var over:MovieClip;
		public var down:MovieClip;
		
		public function ItemList()
		{
			buttonMode = true;
			label_txt.mouseEnabled = false;
			up = up_mc;
			over = over_mc;
			down = down_mc;
			allButtons = [up_mc,down_mc,over_mc];
			hideAllExcept(up_mc);
			draw(width,height);
			addEventListener(Event.ACTIVATE, init);
		}
		
		public function init(event:Event = null):void
		{
			addEventListener(MouseEvent.MOUSE_UP, handleMouse);
			addEventListener(MouseEvent.MOUSE_DOWN, handleMouse);
			addEventListener(MouseEvent.ROLL_OVER, handleMouse);
			addEventListener(MouseEvent.ROLL_OUT, handleMouse);
		}
		
		public function disable():void
		{
			removeEventListener(MouseEvent.MOUSE_UP, handleMouse);
			removeEventListener(MouseEvent.MOUSE_DOWN, handleMouse);
			removeEventListener(MouseEvent.ROLL_OVER, handleMouse);
			removeEventListener(MouseEvent.ROLL_OUT, handleMouse);
		}
		
		public function draw(w:Number,h:Number):void
		{
			scaleX = scaleY = 1;
			for(var i:uint = 0; i < numChildren; i++)
			{
				var obj:DisplayObject = getChildAt(i);
				obj.width = w;
				obj.x = 0;
				obj.y = 0;
			}
		}
		
		private function handleMouse(event:MouseEvent):void
		{
			switch(event.type)
			{
				case MouseEvent.ROLL_OVER :
				
				hideAllExcept(over_mc);
				break;
				case MouseEvent.ROLL_OUT :
				
				hideAllExcept(up_mc);
				break;
				case MouseEvent.MOUSE_DOWN :
				
				hideAllExcept(down_mc);
				break;
				case MouseEvent.MOUSE_UP :
				
				hideAllExcept(over_mc);
				break;
				default :
				trace("sadad");
				break;
			}
		}
		
		public function hideAllExcept(except:MovieClip):void
		{
			for(var i:uint = 0; i < allButtons.length; i++)
			{
				allButtons[i].alpha = (allButtons[i] == except) ? 1 : 0;
			}
		}
		
		public function set label(l:String):void
		{
			_label = l;
			label_txt.text = _label;
		}
		
		public function get label():String
		{
			return _label;
		}
	}
}